package com.xue.domain;

import com.xue.utils.LatLonUtil;
import io.netty.buffer.ByteBuf;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

/**
 * @author xue
 * @create 2022-09-16 17:18
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class AreaInfo extends Info {

    private Integer stationId;

    private Integer lat;

    private Integer lon;

    private Integer ldm;

    private Integer sdm;

    private Double latDouble;

    private Double lonDouble;

    private Double ldmDouble;

    private Double sdmDouble;


    @Override
    public Info decoding(ByteBuf content) {
        AreaInfo areaInfo = (AreaInfo) super.decoding(content);
        areaInfo.setLat(LatLonUtil.translationPoint(areaInfo.getLatDouble()));
        areaInfo.setLon(LatLonUtil.translationPoint(areaInfo.getLonDouble()));
        areaInfo.setLdm(BigDecimal.valueOf(areaInfo.getLdmDouble()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
        areaInfo.setSdm(BigDecimal.valueOf(areaInfo.getSdmDouble()).setScale(0, BigDecimal.ROUND_HALF_UP).intValue());
        return areaInfo;
    }

    @Override
    public Integer getInfoType() {
        return Info.AREA_INFO;
    }

}
